package com.wowangz.cms.dailyoperation.servicemanage.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wowangz.cms.common.utils.DataFormat;
import com.wowangz.cms.common.utils.SysConstant;
import com.wowangz.cms.dailyoperation.servicemanage.pojo.Charge;
import com.wowangz.cms.dailyoperation.servicemanage.pojo.StoreChargeManage;
import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;

/**
 * 服务购买业务类
 * @author yubaode
 *
 */
public class SysServiceInfoService extends BaseService{
	
	/**
	 * 分页查询总条数
	 * @throws SQLException 
	 * @throws NumberFormatException 
	 */
	public long findResultCountByConn(Map<String, Object> map) throws ServiceException, NumberFormatException, SQLException {
		Connection conn = getConnection(Long.parseLong(map.get("storeid").toString()));
		PreparedStatement ps = null;
		ResultSet rs = null;
		
		String startdate = "";
		String enddate ="";
		
		java.util.Date parm_start = null;
		java.sql.Date start_date = null;
		
		java.util.Date parm_end = null;
		java.sql.Date end_date = null;
		
		long count=0;
		try {
			if(!conn.isClosed()){
				StringBuffer sql = new StringBuffer();
				sql.append("select count(1) countnum from sys_service sa ");
				sql.append(" where storeid = ? and statusid = ? ");
				if(map.containsKey("startdate")){
					startdate = map.get("startdate").toString();
					parm_start = DataFormat.parseDate(startdate, DataFormat.DT_YYYY_MM_DD);
					start_date= new java.sql.Date(parm_start.getTime());
					sql.append(" and transtime >= ? ");
				}
				if(map.containsKey("enddate")){
					enddate = map.get("enddate").toString();
					parm_end = DataFormat.parseDate(enddate, DataFormat.DT_YYYY_MM_DD);
					end_date = new java.sql.Date(parm_end.getTime());
					sql.append(" and transtime < ? ");
				}		
				System.out.println(sql.toString());
				ps = conn.prepareStatement(sql.toString());
				ps.setLong(1, Long.parseLong(map.get("storeid").toString()));
				ps.setLong(2, Long.parseLong(map.get("statusid").toString()));
				if(start_date != null && end_date != null){
					ps.setDate(3, start_date);
					ps.setDate(4, end_date);
				}else if(start_date == null && end_date != null){
					ps.setDate(3, end_date);
				}else if(start_date != null && end_date == null){
					ps.setDate(3, start_date);
				}
				
				rs = ps.executeQuery();
				while(rs.next()){
					count = rs.getLong("countnum");
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			close(conn, ps, null, rs);
		}
		return count;
	}
	
	/**
	 * 查询记录集合
	 * @throws SQLException 
	 * @throws NumberFormatException 
	 */
	public List<Charge> findResultListByConn(Map<String, Object> map) throws ServiceException, NumberFormatException, SQLException {
		Connection conn = getConnection(Long.parseLong(map.get("storeid").toString()));
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<Charge> list =  new ArrayList<Charge>();
		String startdate = "";
		String enddate ="";
		java.util.Date parm_start = null;
		java.sql.Date start_date = null;
		java.util.Date parm_end = null;
		java.sql.Date end_date = null;
		try {
			if(!conn.isClosed()){
				StringBuffer sql = new StringBuffer();
				sql.append("select id,transcode,transtime,amount,storeid,buyname,usestatus,inputusername,refundamount from ");
				sql.append(" (select id,transcode,transtime,amount,storeid,buyname,usestatus,inputusername,refundamount from sys_service ");
				sql.append(" where storeid = ? and statusid = ?  ");
				if(map.containsKey("startdate")){
					startdate = map.get("startdate").toString();
					parm_start = DataFormat.parseDate(startdate, DataFormat.DT_YYYY_MM_DD);
					start_date= new java.sql.Date(parm_start.getTime());
					sql.append(" and transtime >= ? ");
				}
				if(map.containsKey("enddate")){
					enddate = map.get("enddate").toString();
					parm_end = DataFormat.parseDate(enddate, DataFormat.DT_YYYY_MM_DD);
					end_date = new java.sql.Date(parm_end.getTime());
					sql.append(" and transtime < ? ");
				}
				sql.append(" order by modifytime desc) c limit ? , ? ");
				System.out.println(sql.toString());
				ps = conn.prepareStatement(sql.toString());
				ps.setLong(1, Long.parseLong(map.get("storeid").toString()));
				ps.setLong(2, Long.parseLong(map.get("statusid").toString()));
				if(start_date != null && end_date != null){
					//如果开始时间和结束时间都不为null，则序号按顺序排
					ps.setDate(3, start_date);
					ps.setDate(4, end_date);
					ps.setInt(5, Integer.parseInt(map.get("startrow").toString()));
					ps.setInt(6, Integer.parseInt(map.get("endrow").toString()));
				}else if(start_date == null && end_date == null){
					//如果开始时间和结束时间都为null，则序号按顺序排
					ps.setInt(3, Integer.parseInt(map.get("startrow").toString()));
					ps.setInt(4, Integer.parseInt(map.get("endrow").toString()));
				}else if(start_date == null && end_date != null){
					ps.setDate(3, end_date);
					ps.setInt(4, Integer.parseInt(map.get("startrow").toString()));
					ps.setInt(5, Integer.parseInt(map.get("endrow").toString()));
				}else if(start_date != null && end_date == null){
					ps.setDate(3, start_date);
					ps.setInt(4, Integer.parseInt(map.get("startrow").toString()));
					ps.setInt(5, Integer.parseInt(map.get("endrow").toString()));
				}
				rs = ps.executeQuery();
				while(rs.next()){
					Charge charge = new Charge();
					charge.setId(rs.getLong("id"));
					charge.setStoreid(rs.getLong("storeid"));
					charge.setAmount(rs.getDouble("amount"));
					charge.setTranscode(rs.getString("transcode"));
					String transtime = rs.getString("transtime");
					java.util.Date parm_transtime = DataFormat.parseDate(transtime, DataFormat.DT_YYYYMMDD_HHMMSS);
					charge.setTranstime(parm_transtime);
					charge.setRefundamount(rs.getDouble("refundamount"));
					charge.setBuyname(rs.getString("buyname"));
					Long usestatus=rs.getLong("usestatus");
					charge.setUsestatusname(SysConstant.ServiceBuyUsestatus.getName(usestatus));
					charge.setInputusername(rs.getString("inputusername"));
					list.add(charge);
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			close(conn, ps, null, rs);
		}
		return list;
	}

	
	/**
	 * 查询记录集合
	 * @throws SQLException 
	 * @throws NumberFormatException 
	 */
	public Charge findResultOneByConn(Map<String, Object> map) throws ServiceException, NumberFormatException, SQLException {
		Connection conn = getConnection(Long.parseLong(map.get("storeid").toString()));
		PreparedStatement ps = null;
		ResultSet rs = null;
		Charge charge=new Charge();
		try {
			if(!conn.isClosed()){
				StringBuffer sql = new StringBuffer();
				sql.append("select id,storeid,transcode,transtime,amount,"
						+ "refundamount,refunddate,buytype,buyname,usestatus from ");
				sql.append(" sys_service ");
				sql.append(" where storeid = ? and statusid = ?  and id=? ");
		
				System.out.println(sql.toString());
				ps = conn.prepareStatement(sql.toString());
				ps.setLong(1, Long.parseLong(map.get("storeid").toString()));
				ps.setLong(2, Long.parseLong(map.get("statusid").toString()));
				ps.setLong(3, Long.parseLong(map.get("id").toString()));
				rs = ps.executeQuery();
				while(rs.next()){
					charge.setId(rs.getLong("id"));
					charge.setStoreid(rs.getLong("storeid"));
					charge.setTranscode(rs.getString("transcode"));
					charge.setAmount(rs.getDouble("amount"));
					charge.setRefundamount(rs.getDouble("refundamount"));
					String refunddate = rs.getString("refunddate");
					Date parm_refunddate = DataFormat.parseDate(refunddate, DataFormat.DT_YYYYMMDD_HHMMSS);
					charge.setRefunddate(parm_refunddate);
					charge.setBuyname(rs.getString("buyname"));
					charge.setBuytype(rs.getLong("buytype"));
					charge.setUsestatus(rs.getLong("usestatus"));
					String transtime = rs.getString("transtime");
					Date parm_transtime = DataFormat.parseDate(transtime, DataFormat.DT_YYYYMMDD_HHMMSS);
					charge.setTranstime(parm_transtime);
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			close(conn, ps, null, rs);
		}
		return charge;
	}
	
	/**
	 * 查询明细数据
	 * @param map
	 * @return
	 * @throws ServiceException
	 * @throws SQLException 
	 * @throws NumberFormatException 
	 */
	public List<StoreChargeManage> findStoreChargeManageForListByConn(Map<String, Object> map) throws ServiceException, NumberFormatException, SQLException{
		Connection conn = getConnection(Long.parseLong(map.get("storeid").toString()));
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<StoreChargeManage> list = new ArrayList<StoreChargeManage>();
		try {
			if(!conn.isClosed()){
				String sql = "select sa.* from sys_service_detail sa "+
							 "inner join sys_service s on s.id=sa.mainid "+
							 "where sa.mainid = ? and s.storeid = ? " ; 
				System.out.println(sql);
				ps = conn.prepareStatement(sql);
				ps.setLong(1, Long.parseLong(map.get("mainid").toString()));
				ps.setLong(2, Long.parseLong(map.get("storeid").toString()));
				rs = ps.executeQuery();
				while(rs.next()){
					StoreChargeManage scm = new StoreChargeManage();
					scm.setId(rs.getLong(1));
					scm.setMainid(rs.getLong(2));
					scm.setServiceid(rs.getLong(3));
					scm.setServicename(rs.getString(4));
					scm.setBuytype(rs.getLong(5));
					scm.setBuycount(rs.getLong(6));
					scm.setUnitprice(rs.getDouble(7));
					scm.setTotalprice(rs.getDouble(8));
					String startdate = rs.getString(9);
					String enddate = rs.getString(10);
					java.util.Date parm_startdate = DataFormat.parseDate(startdate, DataFormat.DT_YYYY_MM_DD);
					java.util.Date parm_enddate = DataFormat.parseDate(enddate, DataFormat.DT_YYYY_MM_DD);
					scm.setStartdate(parm_startdate);
					scm.setEnddate(parm_enddate);
					list.add(scm);
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			close(conn, ps, null, rs);
		}
		return list;
	
	}
	
	/**
	 * 通过后台管理来新增商户购买服务信息记录
	 * @param storeid
	 * @throws SQLException 
	 */
	public Connection insertSysServiceByConn(Charge charge) throws ServiceException, SQLException{
		Connection conn = getConnection(charge.getStoreid());
		Statement st = null;
		ResultSet rs = null;
		String nowtime = DataFormat.formatDate(new Date(), DataFormat.DT_YYYYMMDD_HHMMSS);
		try {
			if(!conn.isClosed()){
				//设置为手动提交事物
				conn.setAutoCommit(false);
				StringBuffer sbf=new StringBuffer("insert into sys_service(storeid,transcode,transtime,amount,");
				if(charge.getRefundamount()!=0){
					sbf.append("refundamount,");
				}
				if(charge.getRefunddate()!=null){
					sbf.append("refunddate,");
				}
				if(charge.getBuytype()!=null){
					sbf.append("buytype,");
				}
				if(charge.getBuyname()!=null){
					sbf.append("buyname,");
				}
				if(charge.getUsestatus()!=null){
					sbf.append("usestatus,");
				}
				sbf.append("statusid,inputusername,inputtime,modifyusername,modifytime) values (");
				sbf.append(charge.getStoreid()+",'"+charge.getTranscode()+"','"+nowtime+"',"+charge.getAmount()+",");
				if(charge.getRefundamount()!=0){
					sbf.append(charge.getRefundamount()+",");
				}
				if(charge.getRefunddate()!=null){
					sbf.append("'"+DataFormat.formatDate(charge.getRefunddate(), DataFormat.DT_YYYYMMDD_HHMMSS)+"',");
				}
				if(charge.getBuytype()!=null){
					sbf.append(charge.getBuytype()+",");
				}
				if(charge.getBuyname()!=null){
					sbf.append("'"+charge.getBuyname()+"',");
				}
				if(charge.getUsestatus()!=null){
					sbf.append(charge.getUsestatus()+",");
				}
				sbf.append(charge.getStatusid()+",'" +charge.getInputusername()+"','"+nowtime+"','"+charge.getModifyusername()+"','"+nowtime+"')");
				String sql = sbf.toString();
				System.out.println(sql);
				st = conn.createStatement();
				st.execute(sql,Statement.RETURN_GENERATED_KEYS);
				rs = st.getGeneratedKeys();
				while(rs.next()){
					charge.setId(rs.getLong(1));
				}
			}
		} catch (SQLException e) {
			try {
				conn.rollback();
				close(conn, null, st, rs);
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}finally{
			close(null, null, st, rs);
		}
		return conn;
	}
	
	/**
	 * 通过后台管理来新增商户购买服务信息
	 * @param storeid
	 * @throws SQLException 
	 */
	public Connection insertSysServiceDetailByConn(StoreChargeManage storeChargeManage,Connection conn) throws ServiceException{
		Statement st = null;
		String startdate = DataFormat.formatDate(storeChargeManage.getStartdate(), DataFormat.DT_YYYYMMDD_HHMMSS);
		String enddate = DataFormat.formatDate(storeChargeManage.getEnddate(), DataFormat.DT_YYYYMMDD_HHMMSS);
		String nowtime = DataFormat.formatDate(new Date(), DataFormat.DT_YYYYMMDD_HHMMSS);
		try {
			if(!conn.isClosed()){
				StringBuffer sb = new StringBuffer();
				sb.append("insert into sys_service_detail(mainid,serviceid,servicename,");
				sb.append("buytype,buycount,unitprice,totalprice");
				if(!"".equals(startdate)){
					sb.append(",startdate");
				}
				if(!"".equals(enddate)){
					sb.append(",enddate");
				}
				if(storeChargeManage.getRefundamount()!=0){
					sb.append(",refundamount");
				}
				if(storeChargeManage.getRefunddate()!=null){
					sb.append(",refunddate");
				}
				sb.append(",statusid,inputusername,inputtime,modifyusername,modifytime");
				sb.append(")values(");
				sb.append(storeChargeManage.getMainid()+","+storeChargeManage.getServiceid());
				sb.append(",'"+storeChargeManage.getServicename()+"',"+storeChargeManage.getBuytype());
				sb.append(","+storeChargeManage.getBuycount()+","+storeChargeManage.getUnitprice()+","+storeChargeManage.getTotalprice());
				
				if(!"".equals(startdate)){
					sb.append(",'"+startdate+"'");
				}
				if(!"".equals(enddate)){
					sb.append(",'"+enddate+"'");
				}
				if(storeChargeManage.getRefundamount()!=0){
					sb.append(","+storeChargeManage.getRefundamount());
				}
				if(storeChargeManage.getRefunddate()!=null){
					sb.append(",'"+storeChargeManage.getRefunddate()+"'");
				}
				sb.append(","+storeChargeManage.getStatusid()+",'" +storeChargeManage.getInputusername()
						+"','"+nowtime+"','"+storeChargeManage.getModifyusername()+"','"+nowtime+"')");
				System.out.println(sb.toString());
				st = conn.createStatement();
				st.execute(sb.toString());
			}
		} catch (SQLException e) {
			try {
				conn.rollback();
				close(conn, null, st, null);
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}finally{
			close(null, null, st, null);
		}
		return conn;
	}
	
	/**
	 * 对数据操作完成后，将手动事物设置成自动事物，并关闭连接
	 * @param conn
	 */
	public void setAutoCommitAndClose(Connection conn){
		try {
			conn.commit();
			conn.setAutoCommit(true);
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			close(conn, null, null, null);
		}
	}
	
	
	/**
	 * 查询该商户是否存在购买相同服务
	 * @param map
	 * @return
	 * @throws ServiceException
	 * @throws SQLException 
	 * @throws NumberFormatException 
	 */
	public boolean findChargeManageForListByConn(Map<String, Object> map) throws ServiceException, NumberFormatException, SQLException{
		Connection conn = getConnection(Long.parseLong(map.get("storeid").toString()));
		PreparedStatement ps = null;
		ResultSet rs = null;
		boolean flag = false;
		java.util.Date date = (java.util.Date)map.get("datetime");
		try {
			if(!conn.isClosed()){
				String sql = "select sa.* from sys_service_detail sa "+
							 "inner join sys_service s on s.id=sa.mainid "+
							 "where sa.serviceid = ? "+
							 "and sa.buytype = ?  and sa.enddate > ? "+
							 "and s.storeid = ? and s.statusid=? " ; 
				System.out.println(sql);
				ps = conn.prepareStatement(sql);
				ps.setLong(1, Long.parseLong(map.get("serviceid").toString()));
				ps.setLong(2, Long.parseLong(map.get("buytype").toString()));
				ps.setDate(3, new java.sql.Date(date.getTime()));
				ps.setLong(4, Long.parseLong(map.get("storeid").toString()));
				ps.setLong(5, Long.parseLong(map.get("statusid").toString()));
				rs = ps.executeQuery();
				if(rs.next()){
					flag = true;
				}else{
					flag = false;
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			close(conn, ps, null, rs);
		}
		return flag;
	}
	
	/**
	 * 通过后台连接jdbc得到最后购买到的服务所花金额总和
	 * @param map
	 * @return
	 * @throws ServiceException
	 * @throws SQLException 
	 * @throws NumberFormatException 
	 */
	public Double findTotalAmountByConn(Map<String, Object> map) throws ServiceException, NumberFormatException, SQLException{
		Connection conn = getConnection(Long.parseLong(map.get("storeid").toString()));
		PreparedStatement ps = null;
		ResultSet rs = null;
		Double totalamount = 0.0;
		try {
			if(!conn.isClosed()){
				String sql = "select sum(totalprice) totalamount from sys_service_detail where mainid= ? " ; 
				System.out.println(sql);
				ps = conn.prepareStatement(sql);
				ps.setLong(1, Long.parseLong(map.get("mainid").toString()));
				rs = ps.executeQuery();
				while(rs.next()){
					totalamount = rs.getDouble("totalamount");
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			close(conn, ps, null, rs);
		}
		return totalamount;
	}
	
	/**
	 * 通过后台连接jdbc进行数据修改
	 * @param sysService
	 * @throws SQLException 
	 */
	public void updateSysServiceByConn(Charge charge) throws ServiceException, SQLException{
		Connection conn = getConnection(charge.getStoreid());
		Statement st = null;
		try {
			if(!conn.isClosed()){
				String sql = "update sys_service set amount = "+charge.getAmount()+
						     " where id = "+charge.getId()+" and storeid = "+charge.getStoreid();
				System.out.println(sql);
				st = conn.createStatement();
				st.executeUpdate(sql);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			close(conn, null, st, null);
		}
	}
	
	public Connection updateSysServiceBuyInfo(Charge charge,Connection conn)throws ServiceException, SQLException{
		Statement st = null;
		ResultSet rs = null;
		String nowtime = DataFormat.formatDate(new Date(), DataFormat.DT_YYYYMMDD_HHMMSS);
		try {
			if(!conn.isClosed()){
				StringBuffer sbf=new StringBuffer("insert into sys_service(storeid,transcode,transtime,amount,");
				if(charge.getRefundamount()!=0){
					sbf.append("refundamount,");
				}
				if(charge.getRefunddate()!=null){
					sbf.append("refunddate,");
				}
				if(charge.getBuytype()!=null){
					sbf.append("buytype,");
				}
				if(charge.getBuyname()!=null){
					sbf.append("buyname,");
				}
				if(charge.getUsestatus()!=null){
					sbf.append("usestatus,");
				}
				sbf.append("statusid,inputusername,inputtime,modifyusername,modifytime) values (");
				sbf.append(charge.getStoreid()+",'"+charge.getTranscode()+"','"+nowtime+"',"+charge.getAmount()+",");
				if(charge.getRefundamount()!=0){
					sbf.append(charge.getRefundamount()+",");
				}
				if(charge.getRefunddate()!=null){
					sbf.append("'"+DataFormat.formatDate(charge.getRefunddate(), DataFormat.DT_YYYYMMDD_HHMMSS)+"',");
				}
				if(charge.getBuytype()!=null){
					sbf.append(charge.getBuytype()+",");
				}
				if(charge.getBuyname()!=null){
					sbf.append("'"+charge.getBuyname()+"',");
				}
				if(charge.getUsestatus()!=null){
					sbf.append(charge.getUsestatus()+",");
				}
				sbf.append(charge.getStatusid()+",'" +charge.getInputusername()+"','"+nowtime+"','"+charge.getModifyusername()+"','"+nowtime+"')");
				String sql = sbf.toString();
				System.out.println(sql);
				st = conn.createStatement();
				st.execute(sql,Statement.RETURN_GENERATED_KEYS);
				rs = st.getGeneratedKeys();
				while(rs.next()){
					charge.setId(rs.getLong(1));
				}
			}
		} catch (SQLException e) {
			try {
				conn.rollback();
				close(conn, null, st, rs);
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}finally{
			close(null, null, st, rs);
		}
		return conn;
	}
	public Connection deteleSysServiceByConn(Charge charge) throws ServiceException, SQLException{
		String sdate = DataFormat.formatDate(new Date(), DataFormat.DT_YYYYMMDD_HHMMSS);
		Connection conn = getConnection(charge.getStoreid());
		Statement st = null;
		try {
			if(!conn.isClosed()){
				conn.setAutoCommit(false);
				StringBuffer sbf = new StringBuffer("update sys_service set statusid = "+charge.getStatusid());
				sbf.append(",modifyusername='"+charge.getModifyusername()+"',modifytime='"+sdate+"'");
				sbf.append(" where id = "+charge.getId()+" and storeid = "+charge.getStoreid());
				String sql=sbf.toString();
				System.out.println(sql);
				st = conn.createStatement();
				st.executeUpdate(sql);
			}
		} catch (SQLException e) {
			try {
				conn.rollback();
				close(conn, null, st, null);
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}finally{
			close(null, null, st, null);
		}
		return conn;
	}
	public Connection deteleSysServiceDetailByConn(Charge charge,Connection conn) throws ServiceException, SQLException{
		String sdate = DataFormat.formatDate(new Date(), DataFormat.DT_YYYYMMDD_HHMMSS);
		Statement st = null;
		try {
			if(!conn.isClosed()){
				StringBuffer sbf = new StringBuffer("update sys_service_detail set statusid = "+charge.getStatusid()+",modifyusername='"+charge.getModifyusername());
				sbf.append("',modifytime='"+sdate+"'"+" where mainid = (select id from sys_service where id="+charge.getId()+" and storeid = "+charge.getStoreid()+")");
				String sql =sbf.toString();
				System.out.println(sql);
				st = conn.createStatement();
				st.executeUpdate(sql);
			}
		} catch (SQLException e) {
			try {
				conn.rollback();
				close(conn, null, st, null);
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		}finally{
			close(null, null, st, null);
		}
		return conn;
	}
	
	/**
	 * 关闭jdbc连接对象
	 * @param conn
	 * @param ps
	 * @param st
	 * @param rs
	 */
	public void close(Connection conn,PreparedStatement ps,Statement st,ResultSet rs){
		if(rs!=null){
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		if(st!=null){
			try {
				st.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		if(ps!=null){
			try {
				ps.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		if(conn!=null){
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * 通过Storeid查询商户收费数据
	 * @param hashMap
	 * @return
	 * @throws ServiceException
	 */
	public List<Charge> queryStoreChargeManageByStoreId(HashMap<String,Object> hashMap) throws ServiceException{
		List<Charge> storeChargeList = this.getSqlSession().selectList("Servicemanage.queryStoreChargeManageByStoreId",hashMap);
		return storeChargeList;
	}
	
	/**
	 * 通过Storeid查询商户功公共收费数据
	 * @param hashMap
	 * @return
	 * @throws ServiceException
	 */
	public List<Charge> queryChargemanageByStoreId(HashMap<String,Object> hashMap) throws ServiceException{
		List<Charge> storeChargeList = this.getSqlSession().selectList("Servicemanage.queryChargemanageByStoreId",hashMap);
		return storeChargeList;
	}
}
